home *** CD-ROM | disk | FTP | other *** search
/ This Disc Bytes! / Power Computing - The Disc 2 - This Disc Bytes.ISO / mac / CodeWarrior 7 Lite for 68K / MacOS Examples / MW AboutBox / About.c next >
Text File  |  1995-12-05  |  27KB  |  907 lines

  1. /************************************************************************/
  2. /*    Project...: C++ and ANSI-C Compiler Environment                     */
  3. /*    Name......: MWAbout.c                                                */
  4. /*    Purpose...: about box                                                */
  5. /*    Copyright.: ©Copyright 1993 by metrowerks inc. All rights reserved. */
  6. /************************************************************************/
  7.  
  8. /* CodeWarrior Lite
  9.  * January 1996
  10.  * © 1996 Metrowerks, Corp.
  11.  */
  12.  
  13. enum  {
  14.     ditl_about = 607,        // about DITL
  15.     ditl_about_items = 8,    // number of items in DITL
  16.     ditl_about_background = 1,    // background about item
  17.     ditl_about_bigbar,        // big tracking bar
  18.     ditl_about_smallbar,    // small tracking bar
  19.     ditl_about_logobox,     // company logo
  20.     ditl_about_namebox,     // company name
  21.     ditl_about_creditsbox,    // credits
  22.     ditl_about_bigbarshadow,    // big bar shadow
  23.     ditl_about_smallbarshadow,    // smallbar shadow
  24.     ditl_about_versionbox,        // version number  +GHD
  25.     ditl_about_helpitem     // hook for ballon help
  26. };
  27.  
  28. #include <GestaltEqu.h>
  29. #include <QDOffscreen.h>
  30. #include <Sound.h>
  31.  
  32. #define        TEXT_AboutVersion    607    
  33. #define        TEXT_Credits        1000
  34.  
  35. #define     WIND_MetroAbout     1000
  36. #define     PICT_Background     1000
  37. #define     PICT_BigBar         1001
  38. #define     PICT_BigBarShadow    2001
  39. #define     PICT_SmallBar        1002
  40. #define     PICT_SmallBarShadow 2002
  41. #define     PICT_LogoBox        3001
  42. #define     PICT_LogoHalf        3002
  43. #define     PICT_LogoWhole        3003
  44. #define     PICT_NameBox        3004
  45. #define     snd_NameBoxClank    3004
  46. #define     Bounce_Distance     10
  47. #define     Fade_Levels         12
  48. typedef struct UserItemRec    {
  49.     long padding1;
  50.     Rect box;
  51.     short padding2;
  52. } UserItemRec;
  53.  
  54. typedef struct DITLRec    {
  55.     short numItems;
  56.     UserItemRec theUserItems[1];
  57. } DITLRec, **DITLHand;
  58.  
  59. void DoAboutBox(Boolean simpleAbout);
  60. void DoSimpleAbout(void);
  61. void SetUpGraphics(void);
  62. void DoAnimation(void);
  63. void CleanUpGraphics(void);
  64. void GetItemRect(short inItem, Rect *outRect);
  65. void DrawPictIntoNewGWorld(short inPICTid, short inDepth,
  66.                            GWorldPtr *outGWorldP);
  67. void DrawTextIntoNewGWorld(short inTEXTid, Rect *inBounds, short inDepth,
  68.                            GWorldPtr *outGWorldP);
  69.  
  70. typedef enum AnimateState  {
  71.     animate_Waiting,
  72.     animate_Active,
  73.     animate_Done
  74. } AnimateState;
  75.  
  76. void MoveOffWorld(GWorldPtr theGWorldP, Rect *currPos, Rect *newPos,
  77.                   Rect *imagePos);
  78. void MoveBar(GWorldPtr theGWorldP, GWorldPtr theShadowWorldP, Rect *inCurrPos,
  79.              Rect *inShadowPos, short inHorizOffset);
  80. void MoveLogoBox(GWorldPtr theGWorldP, Rect *inCurrPos, short inVertOffset);
  81.  
  82. typedef struct BarRec  {
  83.     GWorldPtr theGWorldP;
  84.     GWorldPtr theShadowWorldP;
  85.     Rect currPos;
  86.     Rect shadowPos;
  87. } BarRec;
  88.  
  89. void SetUpBigBar(BarRec *inBigBarRec);
  90. void SetUpSmallBar(BarRec *inSmallBarRec);
  91.  
  92. typedef struct LogoRec    {
  93.     GWorldPtr theGWorldP;
  94.     Rect currPos;
  95.     Rect imagePos;
  96.     short bottomLoc;
  97. } LogoRec;
  98.  
  99. void SetUpLogoBox(LogoRec *inLogoBoxRec);
  100. void SetUpNameBox(LogoRec *inNameBoxRec);
  101.  
  102. typedef struct CreditsRec  {
  103.     GWorldPtr theGWorldP;
  104.     Rect viewRect;
  105.     Rect pictRect;
  106.     short pictHeight;
  107. } CreditsRec;
  108.  
  109. void SetUpCredits(CreditsRec *inCreditsRec);
  110.  
  111. static short Pixel_Depth;
  112. static CWindowPtr aboutBoxWindow;
  113. static PixMapPtr windowPixMapP;
  114. static GWorldPtr drawWorldP;
  115. static PixMapPtr drawPixMapP;
  116. static GWorldPtr backWorldP;
  117. static PixMapPtr backPixMapP;
  118.  
  119. void DoAboutBox(Boolean simpleAbout)
  120. {
  121.     long qdVersion;
  122.     GWorldPtr saveWorld;
  123.     GDHandle saveDevice;
  124.  
  125.     Gestalt(gestaltQuickdrawVersion, &qdVersion);
  126.  
  127.     if (simpleAbout || (qdVersion < gestalt32BitQD) || (FreeMem() < 350000)) {
  128.         GrafPtr savePort;
  129.         //    Machine lacks 32bit QuickDraw or there's not enough memory.
  130.         GetPort(&savePort);
  131.  
  132.         DoSimpleAbout();
  133.  
  134.         SetPort(savePort);
  135.  
  136.     } else {                //    OK to do animated about box.
  137.  
  138.         GetGWorld(&saveWorld, &saveDevice);
  139.  
  140.         SetUpGraphics();
  141.  
  142.         DoAnimation();
  143.  
  144.         CleanUpGraphics();
  145.  
  146.         PurgeMem(maxSize);
  147.         SetGWorld(saveWorld, saveDevice);
  148.     }
  149. }
  150.  
  151. static void DoSimpleAbout(void)
  152. {
  153.     WindowPtr macWindow = GetNewWindow(WIND_MetroAbout, nil, (WindowPtr) -1L);
  154.     PicHandle thePicture;
  155.     Handle theText;
  156.     Rect r;
  157.     long ticks;
  158.  
  159.     ShowWindow(macWindow);
  160.  
  161.     SetPort(macWindow);
  162.  
  163.     thePicture = GetPicture(PICT_Background);
  164.     if (thePicture != nil) {
  165.         r = (**thePicture).picFrame;
  166.  
  167.         DrawPicture(thePicture, &r);
  168.         ReleaseResource((Handle)thePicture);
  169.         
  170.         GetItemRect(ditl_about_versionbox, &r);
  171.         theText = GetResource('TEXT', TEXT_AboutVersion);
  172.         HLock(theText);
  173.         TextSize(9);
  174.         TextFace(bold);
  175.         TextBox(*theText, GetHandleSize(theText), &r, teJustRight);
  176.         ReleaseResource(theText);
  177.         
  178.         Delay(45, &ticks);
  179.  
  180.         thePicture = GetPicture(PICT_LogoWhole);
  181.         GetItemRect(ditl_about_logobox, &r);
  182.         DrawPicture(thePicture, &r);
  183.         ReleaseResource((Handle)thePicture);
  184.         Delay(45, &ticks);
  185.  
  186.         thePicture = GetPicture(PICT_NameBox);
  187.         GetItemRect(ditl_about_namebox, &r);
  188.         DrawPicture(thePicture, &r);
  189.         ReleaseResource((Handle)thePicture);
  190.         Delay(45, &ticks);
  191.  
  192.         while (!Button())
  193.             ;
  194.     }
  195.     DisposeWindow(macWindow);
  196. }
  197.  
  198. static void SetUpGraphics(void)
  199. {
  200.     Rect backRect;
  201.     PixMapHandle thePixMapH;
  202.     Rect versionOffBox, versionWindowBox;
  203.     GWorldPtr    versionWorld;
  204.  
  205.     Pixel_Depth = 8;
  206.  
  207.     //    Make GWorld for offscreen drawing.
  208.  
  209.     GetItemRect(ditl_about_background, &backRect);
  210.     NewGWorld(&drawWorldP, Pixel_Depth, &backRect, nil, nil, 0);
  211.     thePixMapH = GetGWorldPixMap(drawWorldP);
  212.     HLockHi((Handle)thePixMapH);
  213.     LockPixels(thePixMapH);
  214.     drawPixMapP = *thePixMapH;
  215.  
  216.     //    Make GWorld for background.
  217.  
  218.     DrawPictIntoNewGWorld(PICT_Background, Pixel_Depth, &backWorldP);
  219.     thePixMapH = GetGWorldPixMap(backWorldP);
  220.     HLockHi((Handle)thePixMapH);
  221.     LockPixels(thePixMapH);
  222.     backPixMapP = *thePixMapH;
  223.  
  224.     //    Make Window.
  225.  
  226.     aboutBoxWindow = (CWindowPtr) GetNewCWindow(WIND_MetroAbout, nil,
  227.                                                 (WindowPtr) - 1L);
  228.     ShowWindow((WindowPtr)aboutBoxWindow);
  229.     
  230.     HLockHi((Handle)aboutBoxWindow->portPixMap);
  231.     windowPixMapP = *aboutBoxWindow->portPixMap;
  232.  
  233.     //    Draw background in Window.
  234.  
  235.     SetGWorld(aboutBoxWindow, GetMainDevice());
  236.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &backRect,
  237.              &backRect, srcCopy, nil);
  238.              
  239.     // Draw Version Number +GHD
  240.     
  241.     GetItemRect(ditl_about_versionbox, &versionWindowBox);
  242.     versionOffBox = versionWindowBox;
  243.     DrawTextIntoNewGWorld(TEXT_AboutVersion, &versionOffBox, Pixel_Depth, &versionWorld);
  244.     LockPixels(GetGWorldPixMap(versionWorld));
  245.     versionWindowBox.bottom = versionWindowBox.top + versionOffBox.bottom;
  246.     CopyBits((BitMapPtr)*GetGWorldPixMap(versionWorld), (BitMapPtr)windowPixMapP, &versionOffBox,
  247.             &versionWindowBox, adMax, nil);
  248.     DisposeGWorld(versionWorld);
  249. }
  250.  
  251. void SetUpBigBar(BarRec *inBigBarRec)
  252. {
  253.     DrawPictIntoNewGWorld(PICT_BigBar, Pixel_Depth, &inBigBarRec->theGWorldP);
  254.     DrawPictIntoNewGWorld(PICT_BigBarShadow, Pixel_Depth,
  255.                           &inBigBarRec->theShadowWorldP);
  256.  
  257.     GetItemRect(ditl_about_bigbar, &inBigBarRec->currPos);
  258.     GetItemRect(ditl_about_bigbarshadow, &inBigBarRec->shadowPos);
  259.  
  260.     OffsetRect(&inBigBarRec->currPos, -inBigBarRec->shadowPos.right, 0);
  261.     OffsetRect(&inBigBarRec->shadowPos, -inBigBarRec->shadowPos.right, 0);
  262. }
  263.  
  264. void SetUpSmallBar(BarRec *inSmallBarRec)
  265. {
  266.     short barWidth;
  267.  
  268.     DrawPictIntoNewGWorld(PICT_SmallBar, Pixel_Depth,
  269.                           &inSmallBarRec->theGWorldP);
  270.     DrawPictIntoNewGWorld(PICT_SmallBarShadow, Pixel_Depth,
  271.                           &inSmallBarRec->theShadowWorldP);
  272.  
  273.     GetItemRect(ditl_about_smallbar, &inSmallBarRec->currPos);
  274.     GetItemRect(ditl_about_smallbarshadow, &inSmallBarRec->shadowPos);
  275.  
  276.     barWidth = inSmallBarRec->currPos.right - inSmallBarRec->currPos.left;
  277.  
  278.     inSmallBarRec->currPos.left = inSmallBarRec->currPos.right;
  279.     inSmallBarRec->currPos.right += barWidth;
  280.  
  281.     OffsetRect(&inSmallBarRec->shadowPos, barWidth, 0);
  282. }
  283.  
  284. void SetUpLogoBox(LogoRec *inLogoBoxRec)
  285. {
  286.     GetItemRect(ditl_about_logobox, &inLogoBoxRec->currPos);
  287.     inLogoBoxRec->bottomLoc = inLogoBoxRec->currPos.bottom;
  288.     OffsetRect(&inLogoBoxRec->currPos, 0, -inLogoBoxRec->currPos.bottom);
  289. }
  290.  
  291. void SetUpNameBox(LogoRec *inNameBoxRec)
  292. {
  293.     DrawPictIntoNewGWorld(PICT_NameBox, Pixel_Depth,
  294.                           &inNameBoxRec->theGWorldP);
  295.  
  296.     GetItemRect(ditl_about_namebox, &inNameBoxRec->currPos);
  297.     inNameBoxRec->bottomLoc = inNameBoxRec->currPos.bottom;
  298.     OffsetRect(&inNameBoxRec->currPos, 0, -inNameBoxRec->currPos.bottom);
  299.     inNameBoxRec->imagePos.left = inNameBoxRec->imagePos.top = 0;
  300.     inNameBoxRec->imagePos.right = inNameBoxRec->currPos.right -
  301.         inNameBoxRec->currPos.left;
  302.     inNameBoxRec->imagePos.bottom = inNameBoxRec->currPos.bottom -
  303.         inNameBoxRec->currPos.top;
  304. }
  305.  
  306. void SetUpCredits(CreditsRec *inCreditsRec)
  307. {
  308.     PicHandle pictureH;
  309.     Rect picFrame;
  310.     PixMapHandle thePixMapH;
  311.     Rect    creditsBox;
  312.  
  313.     //    The only animation is the credits
  314.     //    Therefore, we can reduce the size of the offscreen worlds for the background
  315.     //    and scratch drawing to just cover the area where the credits are drawn.
  316.  
  317.     DisposeGWorld(backWorldP);
  318.     DisposeGWorld(drawWorldP);
  319.  
  320.     GetItemRect(ditl_about_creditsbox, &inCreditsRec->viewRect);
  321.  
  322.     //    Make GWorld for offscreen drawing.
  323.  
  324.     NewGWorld(&drawWorldP, Pixel_Depth, &inCreditsRec->viewRect, nil, nil, 0);
  325.     thePixMapH = GetGWorldPixMap(drawWorldP);
  326.     HLockHi((Handle)thePixMapH);
  327.     LockPixels(thePixMapH);
  328.     drawPixMapP = *thePixMapH;
  329.  
  330.     //    Make GWorld for background.
  331.  
  332.     NewGWorld(&backWorldP, Pixel_Depth, &inCreditsRec->viewRect, nil,
  333.               GetGWorldDevice(drawWorldP), noNewDevice);
  334.     thePixMapH = GetGWorldPixMap(backWorldP);
  335.     HLockHi((Handle)thePixMapH);
  336.     LockPixels(thePixMapH);
  337.     backPixMapP = *thePixMapH;
  338.     SetGWorld(backWorldP, nil);
  339.     pictureH = GetPicture(PICT_Background);
  340.     picFrame = (**pictureH).picFrame;
  341.     DrawPicture(pictureH, &picFrame);
  342.     ReleaseResource((Handle)pictureH);
  343.  
  344.     //    Make GWorld for credits.
  345.     
  346.     creditsBox = inCreditsRec->viewRect;
  347.     DrawTextIntoNewGWorld(TEXT_Credits, &creditsBox,
  348.             Pixel_Depth, &inCreditsRec->theGWorldP);
  349.             
  350.     inCreditsRec->pictRect.left = 0;
  351.     inCreditsRec->pictRect.top = 0;
  352.     inCreditsRec->pictRect.right = inCreditsRec->viewRect.right -
  353.         inCreditsRec->viewRect.left;
  354.     inCreditsRec->pictRect.bottom = inCreditsRec->viewRect.bottom -
  355.         inCreditsRec->viewRect.top;
  356.         
  357.     inCreditsRec->pictHeight = creditsBox.bottom;
  358. }
  359.  
  360. void MoveBar(GWorldPtr theGWorldP, GWorldPtr theShadowWorldP, Rect *inCurrPos,
  361.              Rect *inShadowPos, short inHorizOffset)
  362. {
  363.     Rect exposedRect, coveredRect, imageRect;
  364.     Rect shadowFront, shadowBack;
  365.     PixMapHandle offPixMapH;
  366.  
  367.     //    Draw to the Window.
  368.  
  369.     SetGWorld(aboutBoxWindow, GetMainDevice());
  370.  
  371.     //    Determine areas exposed and covered by bar as it moves.
  372.  
  373.     exposedRect = coveredRect = *inCurrPos;
  374.     shadowFront = shadowBack = *inShadowPos;
  375.     if (inHorizOffset > 0) {
  376.         exposedRect.right = exposedRect.left + inHorizOffset;
  377.         coveredRect.left = coveredRect.right;
  378.         coveredRect.right += inHorizOffset;
  379.         shadowBack.right = shadowBack.left + inHorizOffset;
  380.         shadowBack.top = coveredRect.bottom;
  381.         shadowFront.left = shadowFront.right;
  382.         shadowFront.right += inHorizOffset;
  383.     } else {
  384.         exposedRect.left = exposedRect.right + inHorizOffset;
  385.         exposedRect.bottom = shadowBack.top;
  386.         coveredRect.right = coveredRect.left;
  387.         coveredRect.left += inHorizOffset;
  388.         shadowBack.left = shadowBack.right + inHorizOffset;
  389.         shadowFront.right = shadowFront.left;
  390.         shadowFront.left += inHorizOffset;
  391.         shadowFront.top = coveredRect.bottom;
  392.     }
  393.     imageRect.left = coveredRect.left;
  394.     imageRect.right = coveredRect.right;
  395.     imageRect.top = 0;
  396.     imageRect.bottom = coveredRect.bottom - coveredRect.top;
  397.  
  398.     //    Restore background over exposed area.
  399.  
  400.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &exposedRect,
  401.              &exposedRect, srcCopy, nil);
  402.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &shadowBack,
  403.              &shadowBack, srcCopy, nil);
  404.  
  405.     //    Draw image at covered area.
  406.  
  407.     offPixMapH = GetGWorldPixMap(theGWorldP);
  408.     LockPixels(offPixMapH);
  409.     CopyBits((BitMapPtr)(*offPixMapH), (BitMapPtr)windowPixMapP, &imageRect,
  410.              &coveredRect, srcCopy, nil);
  411.     UnlockPixels(offPixMapH);
  412.  
  413.     offPixMapH = GetGWorldPixMap(theShadowWorldP);
  414.     LockPixels(offPixMapH);
  415.     CopyBits((BitMapPtr)(*offPixMapH), (BitMapPtr)windowPixMapP, &shadowFront,
  416.              &shadowFront, srcCopy, nil);
  417.     if (inHorizOffset < 0) {
  418.         shadowFront.left = exposedRect.left;
  419.         shadowFront.right = exposedRect.right;
  420.         shadowFront.top = shadowBack.top;
  421.         CopyBits((BitMapPtr)(*offPixMapH), (BitMapPtr)windowPixMapP,
  422.                  &shadowFront, &shadowFront, srcCopy, nil);
  423.     }
  424.     UnlockPixels(offPixMapH);
  425. }
  426.  
  427. void MoveLogoBox(GWorldPtr theGWorldP, Rect *inCurrPos, short inVertOffset)
  428. {
  429.     Rect exposedRect, coveredRect, imageRect;
  430.     RGBColor boxColor =  {
  431.         65535, 52428, 0
  432.     };
  433.  
  434.     //    Draw to the Window.
  435.  
  436.     SetGWorld(aboutBoxWindow, GetMainDevice());
  437.  
  438.     //    Determine areas exposed and covered by bar as it moves.
  439.  
  440.     exposedRect = coveredRect = *inCurrPos;
  441.     if (inVertOffset > 0) {
  442.         exposedRect.bottom = exposedRect.top + inVertOffset;
  443.         coveredRect.top = coveredRect.bottom;
  444.         coveredRect.bottom += inVertOffset;
  445.     } else {
  446.         exposedRect.top = exposedRect.bottom + inVertOffset;
  447.         coveredRect.bottom = coveredRect.top;
  448.         coveredRect.top += inVertOffset;
  449.     }
  450.     imageRect.left = 0;
  451.     imageRect.right = coveredRect.right - coveredRect.left;
  452.     imageRect.top = 0;
  453.     imageRect.bottom = coveredRect.bottom - coveredRect.top;
  454.  
  455.     //    Restore background over exposed area.
  456.  
  457.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &exposedRect,
  458.              &exposedRect, srcCopy, nil);
  459.  
  460.     //    Draw image at covered area.
  461.  
  462.     RGBForeColor(&boxColor);
  463.     PaintRect(&coveredRect);
  464.     ForeColor(blackColor);
  465. }
  466.  
  467. void MoveOffWorld(GWorldPtr theGWorldP, Rect *inCurrPos, Rect *inNewPos,
  468.                   Rect *inOffPos)
  469. {
  470.     Rect drawRect;
  471.     PixMapHandle offPixMapH;
  472.  
  473.     //    Create image in draw world.
  474.  
  475.     SetGWorld(drawWorldP, nil);
  476.  
  477.     //    Restore background at current position.
  478.  
  479.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)drawPixMapP, inCurrPos,
  480.              inCurrPos, srcCopy, nil);
  481.  
  482.     //    Draw image at new position.
  483.  
  484.     offPixMapH = GetGWorldPixMap(theGWorldP);
  485.     LockPixels(offPixMapH);
  486.     CopyBits((BitMapPtr)(*offPixMapH), (BitMapPtr)drawPixMapP, inOffPos,
  487.              inNewPos, srcCopy, nil);
  488.     UnlockPixels(offPixMapH);
  489.  
  490.     //    Draw union of old and new position to Window.
  491.  
  492.     SetGWorld(aboutBoxWindow, GetMainDevice());
  493.     UnionRect(inCurrPos, inNewPos, &drawRect);
  494.     CopyBits((BitMapPtr)drawPixMapP, (BitMapPtr)windowPixMapP, &drawRect,
  495.              &drawRect, srcCopy, nil);
  496. }
  497.  
  498. static void DoAnimation(void)
  499. {
  500.     BarRec theBigBarRec;
  501.     BarRec theSmallBarRec;
  502.     LogoRec theLogoBoxRec;
  503.     LogoRec theNameBoxRec;
  504.     CreditsRec theCreditsRec;
  505.  
  506.     Rect currPos, imagePos;
  507.  
  508.     PicHandle thePictureH;
  509.     SndChannelPtr theSoundChannelP = nil;
  510.     Handle theSoundH = nil;
  511.  
  512.     AnimateState animBigBar = animate_Active;
  513.     AnimateState animSmallBar = animate_Waiting;
  514.     AnimateState animLogoBoxDown = animate_Waiting;
  515.     AnimateState animLogoBoxUp = animate_Waiting;
  516.     AnimateState animNameBoxDown = animate_Waiting;
  517.     AnimateState animNameBoxUp = animate_Waiting;
  518.     AnimateState animCreditsFade = animate_Waiting;
  519.     AnimateState animCreditsScroll = animate_Waiting;
  520.  
  521.     Boolean logoHalfDrawn = false;
  522.     Boolean logoWholeDrawn = false;
  523.  
  524.     RGBColor fadeColor;
  525.     short grayIndex = 0;
  526.     unsigned short grayLevels[Fade_Levels] =  {
  527.         4369, 8738, 17476, 21845, 30583, 34952, 43690, 48059, 52428, 56979,
  528.         61166, 65535
  529.     };
  530.  
  531.     theBigBarRec.theGWorldP = nil;
  532.     theBigBarRec.theShadowWorldP = nil;
  533.     theSmallBarRec.theGWorldP = nil;
  534.     theSmallBarRec.theShadowWorldP = nil;
  535.     theLogoBoxRec.theGWorldP = nil;
  536.     theNameBoxRec.theGWorldP = nil;
  537.     theCreditsRec.theGWorldP = nil;
  538.  
  539.     SetUpBigBar(&theBigBarRec);
  540.     SetUpLogoBox(&theLogoBoxRec);
  541.     theSoundH = GetResource('snd ', snd_NameBoxClank);
  542.     theSmallBarRec.currPos.left = 1000;
  543.  
  544.     while (!Button()) {
  545.         long ticks;
  546.         long endTicks;
  547.         long startTicks = TickCount();
  548.  
  549.         if ((animLogoBoxDown == animate_Waiting) &&
  550.             (theBigBarRec.currPos.left > 100)) {
  551.             animLogoBoxDown = animate_Active;
  552.         }
  553.         if ((animLogoBoxDown == animate_Active) &&
  554.             (theLogoBoxRec.currPos.bottom >=
  555.              theLogoBoxRec.bottomLoc + Bounce_Distance)) {
  556.             animLogoBoxDown = animate_Done;
  557.             animLogoBoxUp = animate_Active;
  558.         }
  559.         if ((animLogoBoxUp == animate_Active) &&
  560.             (theLogoBoxRec.currPos.bottom <= theLogoBoxRec.bottomLoc)) {
  561.             animLogoBoxUp = animate_Done;
  562.         }
  563.         if ((animBigBar == animate_Active) && !logoHalfDrawn &&
  564.             (theBigBarRec.currPos.right > theLogoBoxRec.currPos.right)) {
  565.             SetGWorld(backWorldP, nil);
  566.             thePictureH = GetPicture(PICT_LogoHalf);
  567.             DrawPicture(thePictureH, &theLogoBoxRec.currPos);
  568.             ReleaseResource((Handle)thePictureH);
  569.             logoHalfDrawn = true;
  570.         }
  571.         if ((animBigBar == animate_Active) &&
  572.             theBigBarRec.currPos.left > backWorldP->portRect.right) {
  573.             animBigBar = animate_Done;
  574.             DisposeGWorld(theBigBarRec.theGWorldP);
  575.             theBigBarRec.theGWorldP = nil;
  576.             DisposeGWorld(theBigBarRec.theShadowWorldP);
  577.             theBigBarRec.theShadowWorldP = nil;
  578.             animSmallBar = animate_Active;
  579.             SetUpSmallBar(&theSmallBarRec);
  580.         }
  581.         if ((animSmallBar == animate_Active) && !logoWholeDrawn &&
  582.             (theSmallBarRec.currPos.left < theLogoBoxRec.currPos.left)) {
  583.             SetGWorld(backWorldP, nil);
  584.             thePictureH = GetPicture(PICT_LogoWhole);
  585.             DrawPicture(thePictureH, &theLogoBoxRec.currPos);
  586.             ReleaseResource((Handle)thePictureH);
  587.             logoWholeDrawn = true;
  588.         }
  589.         if ((animNameBoxDown == animate_Waiting) &&
  590.             (theSmallBarRec.currPos.left < 150)) {
  591.             animNameBoxDown = animate_Active;
  592.             SetUpNameBox(&theNameBoxRec);
  593.         }
  594.         if ((animNameBoxDown == animate_Active) &&
  595.             (theNameBoxRec.currPos.bottom >=
  596.              theNameBoxRec.bottomLoc + Bounce_Distance)) {
  597.             animNameBoxDown = animate_Done;
  598.             animNameBoxUp = animate_Active;
  599.         }
  600.         if ((animNameBoxUp == animate_Active) &&
  601.             (theNameBoxRec.currPos.bottom <= theNameBoxRec.bottomLoc)) {
  602.             OSErr err;
  603.             animNameBoxUp = animate_Done;
  604.             DisposeGWorld(theNameBoxRec.theGWorldP);
  605.             theNameBoxRec.theGWorldP = nil;
  606.             if (theSoundH != nil) {
  607.                 err = SndNewChannel(&theSoundChannelP, sampledSynth, initMono,
  608.                                     nil);
  609.                 if (err == noErr)
  610.                     SndPlay(theSoundChannelP, (SndListHandle)theSoundH, true);
  611.             }
  612.         }
  613.         if ((animSmallBar == animate_Active) &&
  614.             (theSmallBarRec.shadowPos.right < backWorldP->portRect.left)) {
  615.             animSmallBar = animate_Done;
  616.             DisposeGWorld(theSmallBarRec.theGWorldP);
  617.             theSmallBarRec.theGWorldP = nil;
  618.             DisposeGWorld(theSmallBarRec.theShadowWorldP);
  619.             theSmallBarRec.theShadowWorldP = nil;
  620.  
  621.             if (theSoundChannelP != nil) {
  622.                 SndDisposeChannel(theSoundChannelP, true);
  623.                 theSoundChannelP = nil;
  624.             }
  625.             if (theSoundH != nil) {
  626.                 ReleaseResource(theSoundH);
  627.                 theSoundH = nil;
  628.             }
  629.             animCreditsFade = animate_Active;
  630.             SetUpCredits(&theCreditsRec);
  631.         }
  632.         if ((animCreditsFade == animate_Active) &&
  633.             (grayIndex >= Fade_Levels)) {
  634.             animCreditsFade = animate_Done;
  635.             Delay(90, &ticks);
  636.             animCreditsScroll = animate_Active;
  637.         }
  638.         if ((animCreditsScroll == animate_Active) &&
  639.             (theCreditsRec.pictRect.top > theCreditsRec.pictHeight)) {
  640.             theCreditsRec.pictRect.top = 1;
  641.             theCreditsRec.pictRect.bottom = theCreditsRec.viewRect.bottom -
  642.                 theCreditsRec.viewRect.top + 1;
  643.         }
  644.         if (animBigBar == animate_Active) {
  645.             MoveBar(theBigBarRec.theGWorldP, theBigBarRec.theShadowWorldP,
  646.                     &theBigBarRec.currPos, &theBigBarRec.shadowPos, 1);
  647.             theBigBarRec.currPos.left++;
  648.             theBigBarRec.currPos.right++;
  649.             theBigBarRec.shadowPos.left++;
  650.             theBigBarRec.shadowPos.right++;
  651.         }
  652.         if (animLogoBoxDown == animate_Active) {
  653.             MoveLogoBox(theLogoBoxRec.theGWorldP, &theLogoBoxRec.currPos, 1);
  654.             theLogoBoxRec.currPos.top++;
  655.             theLogoBoxRec.currPos.bottom++;
  656.         }
  657.         if (animLogoBoxUp == animate_Active) {
  658.             MoveLogoBox(theLogoBoxRec.theGWorldP, &theLogoBoxRec.currPos, -1);
  659.             theLogoBoxRec.currPos.top--;
  660.             theLogoBoxRec.currPos.bottom--;
  661.         }
  662.         if (animSmallBar == animate_Active) {
  663.             MoveBar(theSmallBarRec.theGWorldP, theSmallBarRec.theShadowWorldP,
  664.                     &theSmallBarRec.currPos, &theSmallBarRec.shadowPos, -1);
  665.             theSmallBarRec.currPos.left--;
  666.             theSmallBarRec.currPos.right--;
  667.             theSmallBarRec.shadowPos.left--;
  668.             theSmallBarRec.shadowPos.right--;
  669.         }
  670.         if (animNameBoxDown == animate_Active) {
  671.             currPos = theNameBoxRec.currPos;
  672.             theNameBoxRec.currPos.top++;
  673.             theNameBoxRec.currPos.bottom++;
  674.             imagePos = theNameBoxRec.imagePos;
  675.             MoveOffWorld(theNameBoxRec.theGWorldP, &currPos,
  676.                          &theNameBoxRec.currPos, &imagePos);
  677.         }
  678.         if (animNameBoxUp == animate_Active) {
  679.             currPos = theNameBoxRec.currPos;
  680.             theNameBoxRec.currPos.top--;
  681.             theNameBoxRec.currPos.bottom--;
  682.             imagePos = theNameBoxRec.imagePos;
  683.             MoveOffWorld(theNameBoxRec.theGWorldP, &currPos,
  684.                          &theNameBoxRec.currPos, &imagePos);
  685.         }
  686.         if (animCreditsFade == animate_Active) {
  687.             PixMapHandle thePixMapH;
  688.  
  689.             Delay(3, &ticks);
  690.             SetGWorld(drawWorldP, nil);
  691.  
  692.             thePixMapH = GetGWorldPixMap(theCreditsRec.theGWorldP);
  693.             LockPixels(thePixMapH);
  694.             CopyBits((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP,
  695.                      &theCreditsRec.pictRect, &theCreditsRec.viewRect,
  696.                      srcCopy, nil);
  697.             UnlockPixels(thePixMapH);
  698.  
  699.             fadeColor.red = fadeColor.blue = fadeColor.green =
  700.                 grayLevels[grayIndex++];
  701.             RGBForeColor(&fadeColor);
  702.             PenMode(adMin);
  703.             PaintRect(&theCreditsRec.viewRect);
  704.             PenMode(patCopy);
  705.             ForeColor(blackColor);
  706.  
  707.             CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)drawPixMapP,
  708.                      &theCreditsRec.viewRect, &theCreditsRec.viewRect, adMax,
  709.                      nil);
  710.  
  711.             SetGWorld(aboutBoxWindow, GetMainDevice());
  712.             CopyBits((BitMapPtr)drawPixMapP, (BitMapPtr)windowPixMapP,
  713.                      &theCreditsRec.viewRect, &theCreditsRec.viewRect,
  714.                      srcCopy, nil);
  715.         }
  716.         if (animCreditsScroll == animate_Active) {
  717.             PixMapHandle thePixMapH;
  718.             short i, j;
  719.             short creditsWidth =
  720.                 theCreditsRec.viewRect.right -theCreditsRec.viewRect.left -1;
  721.             Rect wrapViewRect, wrapPictRect;
  722.  
  723.             SetGWorld(drawWorldP, nil);
  724.  
  725.             theCreditsRec.pictRect.top += 1;
  726.             theCreditsRec.pictRect.bottom += 1;
  727.  
  728.             thePixMapH = GetGWorldPixMap(theCreditsRec.theGWorldP);
  729.             LockPixels(thePixMapH);
  730.             if (theCreditsRec.pictRect.bottom <= theCreditsRec.pictHeight) {
  731.                 CopyBits((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP,
  732.                          &theCreditsRec.pictRect, &theCreditsRec.viewRect,
  733.                          srcCopy, nil);
  734.             } else {
  735.                 wrapViewRect = theCreditsRec.viewRect;
  736.                 wrapViewRect.top = wrapViewRect.bottom -
  737.                     (theCreditsRec.pictRect.bottom -
  738.                      theCreditsRec.pictHeight);
  739.                 wrapPictRect = theCreditsRec.pictRect;
  740.                 wrapPictRect.top = 0;
  741.                 wrapPictRect.bottom = wrapPictRect.top +
  742.                     (wrapViewRect.bottom - wrapViewRect.top);
  743.                 CopyBits((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP,
  744.                          &theCreditsRec.pictRect, &theCreditsRec.viewRect,
  745.                          srcCopy, nil);
  746.                 CopyBits((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP,
  747.                          &wrapPictRect, &wrapViewRect, srcCopy, nil);
  748.             }
  749.             UnlockPixels(thePixMapH);
  750.  
  751.             PenMode(adMin);                    // Fade out at top and fade in at bottom
  752.             j = Fade_Levels - 1;
  753.             for (i = 0; i < j; i++) {
  754.                 fadeColor.red = fadeColor.blue = fadeColor.green =
  755.                     grayLevels[i];
  756.                 RGBForeColor(&fadeColor);
  757.                 MoveTo(theCreditsRec.viewRect.left,
  758.                        theCreditsRec.viewRect.top + i);
  759.                 Line(creditsWidth, 0);
  760.                 MoveTo(theCreditsRec.viewRect.left,
  761.                        theCreditsRec.viewRect.bottom - i - 1);
  762.                 Line(creditsWidth, 0);
  763.             }
  764.             ForeColor(blackColor);
  765.             PenMode(patCopy);
  766.  
  767.             CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)drawPixMapP,
  768.                      &theCreditsRec.viewRect, &theCreditsRec.viewRect, adMax,
  769.                      nil);
  770.             SetGWorld(aboutBoxWindow, GetMainDevice());
  771.             CopyBits((BitMapPtr)drawPixMapP, (BitMapPtr)windowPixMapP,
  772.                      &theCreditsRec.viewRect, &theCreditsRec.viewRect,
  773.                      srcCopy, nil);
  774.         }
  775.         endTicks = TickCount(); //    Timing loop.
  776.         if (endTicks == startTicks) {    //    TickCount must change during each pass thru animation loop.
  777.             while (endTicks == TickCount())
  778.                 ;            //    this puts an upper speed limit on the animation rate.
  779.         }
  780.     }
  781.  
  782.     // Finished animation (user clicked). Flush the mousedown events
  783.  
  784.     FlushEvents(mDownMask | mUpMask | keyDownMask | keyUpMask | autoKeyMask,
  785.                 0);
  786.  
  787.     //    Dispose of all GWorlds (if they haven't already been disposed).
  788.  
  789.     if (theBigBarRec.theGWorldP != nil)
  790.         DisposeGWorld(theBigBarRec.theGWorldP);
  791.     if (theBigBarRec.theShadowWorldP != nil)
  792.         DisposeGWorld(theBigBarRec.theShadowWorldP);
  793.     if (theSmallBarRec.theGWorldP != nil)
  794.         DisposeGWorld(theSmallBarRec.theGWorldP);
  795.     if (theSmallBarRec.theShadowWorldP != nil)
  796.         DisposeGWorld(theSmallBarRec.theShadowWorldP);
  797.     if (theLogoBoxRec.theGWorldP != nil)
  798.         DisposeGWorld(theLogoBoxRec.theGWorldP);
  799.     if (theNameBoxRec.theGWorldP != nil)
  800.         DisposeGWorld(theNameBoxRec.theGWorldP);
  801.     if (theCreditsRec.theGWorldP != nil)
  802.         DisposeGWorld(theCreditsRec.theGWorldP);
  803.  
  804.     if (theSoundChannelP != nil)
  805.         SndDisposeChannel(theSoundChannelP, true);
  806.     if (theSoundH != nil)
  807.         ReleaseResource(theSoundH);
  808. }
  809.  
  810. static void CleanUpGraphics(void)
  811. {
  812.     DisposeGWorld(drawWorldP);
  813.     DisposeGWorld(backWorldP);
  814.     DisposeWindow((WindowPtr)aboutBoxWindow);
  815. }
  816.  
  817. void GetItemRect(short inItem, Rect *outRect)
  818. {
  819.     DITLHand theDITL;
  820.  
  821.     theDITL = (DITLHand) GetResource('DITL', ditl_about);
  822.     *outRect = (**theDITL).theUserItems[inItem - 1].box;
  823. }
  824.  
  825. void DrawPictIntoNewGWorld(short inPICTid, short inDepth,
  826.                            GWorldPtr *outGWorldP)
  827. {
  828.     PicHandle thePicture;
  829.     Rect picFrame;
  830.     GWorldPtr saveWorld;
  831.     GDHandle saveDevice;
  832.     OSErr err;
  833.  
  834.     thePicture = GetPicture(inPICTid);
  835.     picFrame = (**thePicture).picFrame;
  836.  
  837.     err = NewGWorld(outGWorldP, inDepth, &picFrame, nil,
  838.                     GetGWorldDevice(drawWorldP), noNewDevice);
  839.  
  840.     GetGWorld(&saveWorld, &saveDevice);
  841.     SetGWorld (*outGWorldP, nil);
  842.     LockPixels(GetGWorldPixMap(*outGWorldP));
  843.     DrawPicture(thePicture, &picFrame);
  844.     UnlockPixels(GetGWorldPixMap(*outGWorldP));
  845.     SetGWorld(saveWorld, saveDevice);
  846.  
  847.     ReleaseResource((Handle)thePicture);
  848. }
  849.  
  850. void DrawTextIntoNewGWorld(short inTEXTid, Rect *ioBounds, short inDepth,
  851.                            GWorldPtr *outGWorldP)
  852. {
  853.     Handle theText;
  854.     TEHandle    theTE;
  855.     StScrpHandle    theStyle;
  856.     GWorldPtr saveWorld;
  857.     GDHandle saveDevice;
  858.     OSErr err;
  859.     
  860.         // Put Text in a TERecord
  861.     
  862.     TextFont(applFont);    
  863.     TextSize(9);
  864.     theTE = TEStylNew(ioBounds, ioBounds);
  865.     theText = GetResource('TEXT', inTEXTid);
  866.     theStyle = (StScrpHandle) GetResource('styl', inTEXTid);
  867.     HLock(theText);
  868.     HidePen();
  869.     TEStylInsert(*theText, GetHandleSize(theText), theStyle, theTE);
  870.     ShowPen();
  871.     ReleaseResource(theText);
  872.     if (theStyle != nil) {
  873.         ReleaseResource((Handle)theStyle);
  874.     }
  875.     TESetJust(teJustRight, theTE);
  876.     TECalText(theTE);
  877.     
  878.         // Determine height of the Text
  879.  
  880.     ioBounds->right = ioBounds->right - ioBounds->left;
  881.     ioBounds->left = ioBounds->top = 0;
  882.     ioBounds->bottom = TEGetHeight((**theTE).nLines, 0, theTE);
  883.     
  884.         // Create new GWorld that is the height of the Text
  885.     err = NewGWorld(outGWorldP, inDepth, ioBounds, nil,
  886.                     GetGWorldDevice(drawWorldP), noNewDevice);
  887.  
  888.     GetGWorld(&saveWorld, &saveDevice);
  889.     SetGWorld (*outGWorldP, nil);
  890.     LockPixels(GetGWorldPixMap(*outGWorldP));
  891.     
  892.     EraseRect(ioBounds);
  893.  
  894.         // Draw Text inside GWorld
  895.     (**theTE).viewRect = *ioBounds;
  896.     (**theTE).destRect = *ioBounds;
  897.     (**theTE).inPort = (GrafPtr) *outGWorldP;
  898.     TEUpdate(ioBounds, theTE);
  899.     TEDispose(theTE);
  900.     
  901.     InvertRect(ioBounds);            // White letters on black background
  902.  
  903.     UnlockPixels(GetGWorldPixMap(*outGWorldP));
  904.     SetGWorld(saveWorld, saveDevice);
  905. }
  906.  
  907.